package com.webdemo06.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import com.webdemo06.pojo.User;
import com.webdemo06.util.HibernateHandler;

public class AddUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = new User();
		user.setName(request.getParameter("name"));
		Session session = HibernateHandler.newInstance().getCurrentSession();
		session.beginTransaction();
		session.save(user);
		session.getTransaction().commit();
		response.sendRedirect(this.getServletContext().getContextPath()+"/QueryUser");
	}

}
